package com.cloud.bc.service.impl;

import com.cloud.bc.model.entity.BcCategoryGroups;
import com.cloud.bc.mapper.BcCategoryGroupsMapper;
import com.cloud.bc.service.BcCategoryGroupsService;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.math.BigInteger;
import java.util.List;

/**
 * 分类组
 *
 * @author douhaichao code generator
 * @date 2021-01-03 11:24:38
 */
@Service
@AllArgsConstructor
public class BcCategoryGroupsServiceImpl extends ServiceImpl<BcCategoryGroupsMapper, BcCategoryGroups> implements BcCategoryGroupsService {

    /**
     * 根据对象属性查找满足条件的第一条数据     *      * @return
     */
    @Override
    public BcCategoryGroups selectOne(BcCategoryGroups req) {
        QueryWrapper queryWrapper = new QueryWrapper<BcCategoryGroups>();
        queryWrapper.setEntity(req);
        return baseMapper.selectOne(queryWrapper);
    }

    /**
     * 根据条件查询所有
     */
    @Override
    public List<BcCategoryGroups> selectAll(BcCategoryGroups req) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.setEntity(req);
        return baseMapper.selectList(queryWrapper);
    }

    /**
     * 根据对象查询所有分页数据(精确查询)     *      * @return
     */
    @Override
    public IPage<BcCategoryGroups> selectPage(Page page, BcCategoryGroups req) {
        IPage<BcCategoryGroups> list = baseMapper.selectPage(
                page,
                new QueryWrapper<BcCategoryGroups>().setEntity(req));
        return list;
    }

    /**
     * 根据对象查询所有分页数据(模糊查询)     *      * @return
     */
    @Override
    public IPage<BcCategoryGroups> selectPageByLike(Page page, BcCategoryGroups req) {
        QueryWrapper queryWrapper = new QueryWrapper();

        if (null != req.getId()) {
            queryWrapper.eq("id", req.getId());
        }

        if (!StrUtil.isEmpty(req.getAlias())) {
            queryWrapper.like("alias", req.getAlias());
        }

        if (!StrUtil.isEmpty(req.getName())) {
            queryWrapper.like("name", req.getName());
        }

        if (!StrUtil.isEmpty(req.getModule())) {
            queryWrapper.like("module", req.getModule());
        }
        IPage<BcCategoryGroups> list = baseMapper.selectPage(page, queryWrapper);
        return list;
    }

    /**
     * 根据条件统计数据量     *      * @return
     */
    @Override
    public int count(BcCategoryGroups req) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.setEntity(req);
        return baseMapper.selectCount(queryWrapper);
    }
}
